package pp.infrastructure.http;

import lombok.Data;

/**
 * HTTP 接口统一响应格式
 */
@Data
public class Response<T> {

    public static Integer CODE_SUCCESS = 200;
    public static Integer CODE_FAIL = 500;

    private Integer code;
    private String message;
    private T data;

    private Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Response<T> fail() {
        return fail("请求失败");
    }

    public static <T> Response<T> fail(String message) {
        return new Response<>(CODE_FAIL, message, null);
    }

    public static <T> Response<T> success(T data, String message) {
        return new Response<>(CODE_SUCCESS, message, data);
    }

    public static <T> Response<T> success(String message) {
        return new Response<>(CODE_SUCCESS, message, null);
    }


}
